# # from celery_task.task1 import add
# from celery_task.task2 import mutile
# ret2 = mutile.delay(2,3)
# print(ret2)
#
# #执行延迟任务
# from celery_task.task2 import mutile
# from datetime import datetime,timedelta
# #必须是utc时间，timedelta是时间对象，10秒后，days=,
# eta = datetime.utcnow()+timedelta(seconds=30)
# ret=mutile.apply_async(args=(10,5),eta=eta)
# print(ret)
# import openpyxl
import os


# print(path)

def excel_export(name):
    from xlwt import *
    import os
    """
    导出excel表格
    """
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    path = os.path.join(BASE_DIR, 'studentSystemt', 'studentSystemt', 'media', 'students_excels', f'{name}.xlsx')
    # list_obj = models.User.objects.filter(stuclass='200732')
    list_obj=[
        {'id':1,'name':'lhz',"username":'31201',"stuclass":'200732'},
        {'id':2,'name':'zzh',"username":'31202',"stuclass":'200732'},
        {'id': 3, 'name': 'yf', "username": '31203', "stuclass": '200732'},
        {'id': 4, 'name': '刘海樟', "username": '31204', "stuclass": '200732'},
              ]
    if list_obj:
        # 创建工作薄
        ws = Workbook(encoding='utf-8')
        w = ws.add_sheet(u"数据报表第一页")
        w.write(0, 0, "id")
        w.write(0, 1, u"姓名")
        w.write(0, 2, u"学号")
        w.write(0, 3, u"班级")
        # 写入数据
        excel_row = 1
        for obj in list_obj:
            w.write(excel_row, 0, obj['id'])
            w.write(excel_row, 1, obj['name'])
            w.write(excel_row, 2, obj['username'])
            w.write(excel_row, 3, obj['stuclass'])
            excel_row += 1
        # # 检测文件是够存在
        # # 方框中代码是保存本地文件使用，如不需要请删除该代码
        # ###########################

        # exist_file = os.path.exists("test.xls")
        # if exist_file:
        #     os.remove(r"test.xls")
        # ws.save("test.xls")
        # ############################
        # sio = StringIO.StringIO()
        # ws.save(sio)
        # sio.seek(0)
        # response = HttpResponse(sio.getvalue(), content_type='application/vnd.ms-students_excels')
        # response['Content-Disposition'] = 'attachment; filename=test.xls'
        # response.write(sio.getvalue())
        ws.save(path)
        return 'okok'
excel_export('lhz')
print(111)